<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/include/taglib.jsp" %>
<!DOCTYPE html>
<html>
<head>
<title>编辑</title>
<%@ include file="/include/header.jsp"%>
<script src="${ctx}/js/lib/jquery-ui.custom.js" type="text/javascript"></script>
<script src="${ctx}/component/My97DatePicker/WdatePicker.js" type="text/javascript"></script>
</head>
<body>
	<div class="dialog_main">
		<div class="b_box">
			<form id="${simpleBeanName}Form">
				<input type="hidden" name="CSRFToken" value="${r"${csrfToken}"}" />
				<input type="hidden" name="${columnList[0].javaPropertyName}" value="${r"${"}${simpleBeanName+"."+columnList[0].javaPropertyName}${r"}"}" />
				<table class="c_table m_t10">
						<#list columnList as column>
						<tr>
							<td class="t_tit">${column.dbColumnComment}：</td>
							<td><input type="text" class="input_txt" id="${column.javaPropertyName}" name="${column.javaPropertyName}" data-validaterole="${column.javaPropertyName}" data-rule="${column.javaPropertyName}" value="${r"${"}${simpleBeanName+"."+column.javaPropertyName}${r"}"}" data-param='{"code" : "mmm","ml":${column.dbColumnPrecision}}' data-message='最大不能超过<!=ml!>' /></td>
						</tr>					
						</#list>
				</table>					
			</form>
		</div>
		<div class="action_box m_t10 t_c">
			<input type="button" class="save_btn" id="editBtn" value="保存" />
		</div>
	</div>

	<script type="text/javascript">
	// 验证
	seajs.use(["component/validate", "component/tip"], function(validate, tip) {
		var ntip = function() {
			// 定义一个提示对象
			return new tip({});
		};

		// 定义一个验证对象
		var d = new validate({
			con: "#${simpleBeanName}Form",
			// 验证容器
			ntip: ntip,
			onSubmit: "#editBtn" // 提交按钮
		});

		// 设置拼装规则: 这里加上各个验证规则
		<#list columnList as column>
		d.setValidateRule({ ${column.javaPropertyName}: ["isBlank", "checkLen"] });
		</#list>
	
		// 注册保存按钮事件
		d.bind("onsubmit", function() {
				// 序列化表单参数
				var serializedForm = $("#${simpleBeanName}Form").serialize();
				$.post("${ctx}/${simpleBeanName}/edit.do", serializedForm, function(result) {
					if ("succ" == result) {
						alert("操作成功");
						// 刷新列表页面
						parent.location.replace("${ctx}/${simpleBeanName}/list.do?ts=" + new Date().getTime()); //如果发表成功则跳到列表界面 
						// 关闭弹窗窗口
						parent.${simpleBeanName}Dialog.close();
					} else if ("notThroughSecurityCheck" == result["isThroughSecurityCheck"]) { // 如果不通过安全检查
						var mess = result["mess"];
						$.post("${ctx}/common/notThroughSecurityCheck.do?ts=" + new Date().getTime(), mess, function(res) {
							alert(res);
						}, "json");

					} else {
						alert(result);
					}
				},
				"json");
	
		});
	});
	</script>
</body>
</html>